package br.mg.bhe.ftpobre.fs.data.xml;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

import org.w3c.dom.Document;

import com.sun.org.apache.xml.internal.serialize.OutputFormat;
import com.sun.org.apache.xml.internal.serialize.XMLSerializer;

/**
 * 
 * @author Aureliano
 */
@SuppressWarnings("restriction")
public final class XmlWriter {

	private XmlWriter() {
		super();
	}
	
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public static void write(IDocumentParser parser, Object data, File outcome) throws IOException {
		writeToXml(parser.parse(data), outcome);
	}
	
	private static void writeToXml(Document doc, File outcome) throws IOException {
		XMLSerializer serializer = new XMLSerializer(
				new FileOutputStream(outcome), new OutputFormat(doc, "utf-8", true));
		serializer.serialize(doc);
	}
}